#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	int sz = n;
	vector<int> v;
	while (n--) {
		int a;
		cin >> a;
		v.push_back(a);
	}
	long long pay = 0;
	int Min = 0;
	if (sz == 1)
	{
		cout << v[0];
		return 0;
	}
	else if (sz == 2) {
		cout << min(v[1], v[0]);
		return 0;
	}
	else if (sz == 3)
	{
		cout << min(v[1], v[0] + v[2]);
		return 0;
	}
	else
	{
		if (v[1] + v[3] < v[0] + v[2])
			Min = 1;
		else
			Min = 0;
	}
	for (int i = Min;;)
	{
		pay += v[i];
		if (i == sz - 1 || i == sz - 2)
		{
			break;
		}
		if (v[i + 1] > v[i + 2])
		{
			i += 2;
		}
		else if (v[i + 1] < v[i + 2])
		{
			i++;
		}
		else
		{
			i += 2;
		}
	}
	cout << pay;
	return 0;
}